package cn.itcast.travel.service.impl;

import cn.itcast.travel.dao.UserDao;
import cn.itcast.travel.dao.impl.UserDaoImpl;
import cn.itcast.travel.domain.User;
import cn.itcast.travel.service.UserService;

import java.io.IOException;

public class UserServiceImpl implements UserService {
    private UserDao userDao=new UserDaoImpl();

    @Override
    public boolean regist(User user) throws IOException {
        User user1 = userDao.FindByUsername(user.getUsername());
        if (user1!=null){
            return false;
        }else {

            userDao.save(user);
        }



        return true;
    }

    @Override
    public boolean active(String code) {
        User   user=userDao.FindByCode(code);
        if (user!=null){
            userDao.updateStatus(user);
            return true;
        }else {
            return false;
        }

    }

    @Override
    public User login(User user) {

        return userDao.FindUsernameAndPassword(user.getUsername(),user.getPassword());
    }

    @Override
    public User findUserByUserName(String username) {
        return userDao.FindByUsername(username);
    }
}
